package com.example.practice1;


import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.graphics.Color;
import android.os.Bundle;
import android.view.SurfaceControl;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    private LinearLayout linearLayout1,linearLayout2,linearLayout3,linearLayout4;

    private FragmentManager fragmentManager;
    private FragmentTransaction fragmentTransaction;

    @Override
    protected void onCreate(Bundle savedInstanceState)  {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initEvent();
        linearLayout1.setBackgroundColor(Color.rgb(155,155,155));
        fragmentManager = getSupportFragmentManager();
        fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.id_content, new MessageFragment());
        fragmentTransaction.commit();
    }
    private void initEvent(){
        linearLayout1.setOnClickListener(this);
        linearLayout2.setOnClickListener(this);
        linearLayout3.setOnClickListener(this);
        linearLayout4.setOnClickListener(this);
    }

    private void initView(){
        linearLayout1 = findViewById(R.id.linearLayout1);
        linearLayout2 = findViewById(R.id.linearLayout2);
        linearLayout3 = findViewById(R.id.linearLayout3);
        linearLayout4 = findViewById(R.id.linearLayout4);
    }

    @Override
    public void onClick(View view){
        setAllColor();
        fragmentManager = getSupportFragmentManager();
        fragmentTransaction = fragmentManager.beginTransaction();
        switch (view.getId()){
            case R.id.linearLayout1:
                fragmentTransaction.replace(R.id.id_content,new MessageFragment());
                linearLayout1.setBackgroundColor(Color.rgb(155,155,155));
                break;

            case R.id.linearLayout2:
                fragmentTransaction.replace(R.id.id_content,new CommunicationFragment());
                linearLayout2.setBackgroundColor(Color.rgb(155,155,155));
                break;
            case R.id.linearLayout3:
                fragmentTransaction.replace(R.id.id_content,new FindFragment());
                linearLayout3.setBackgroundColor(Color.rgb(155,155,155));
                break;
            case R.id.linearLayout4:
                fragmentTransaction.replace(R.id.id_content,new MeFragment());
                linearLayout4.setBackgroundColor(Color.rgb(155,155,155));
                break;
        }
        fragmentTransaction.commit();
    }
    private void setAllColor() {
        linearLayout1.setBackgroundColor(Color.WHITE);
        linearLayout2.setBackgroundColor(Color.WHITE);
        linearLayout3.setBackgroundColor(Color.WHITE);
        linearLayout4.setBackgroundColor(Color.WHITE);
    }
}
